<?php
defined('BASEPATH') OR exit('No direct script access allowed');


/**
 *  author:yuchong
 *  手动区块处理
 */
class Section extends Admin_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->model("admin/section_model");
    }

    /**
    *   区块首页展示
     */
	public function index()
	{
        $classid = $this->input->get("classid") ? intval($this->input->get('classid')) : 1;
        $data['section_class'] = $this->get_section_class();
        $data['section_data']  = $this->section_model->getByCid($classid);
        $this->load->view("admin/section_list", $data);
	}


    /**
     *  编辑区块内容
     */
    public function edit()
    {
        $sid = $this->input->get("sid") ? intval($this->input->get('sid')) : 0;
        $data['section_class'] = $this->get_section_class();
        $data['section_data']  = $this->section_model->getBySid($sid);
        $this->load->view("admin/section_edit", $data);
    }

    /**
     *  保存区块内容
     */
    public function save()
    {
        $cid = $this->input->post('cid');
        $sid = $this->input->post('sid');
        $data = $this->input->post('data');
        $up_data = array(
            'data' => $data,
            'modified' => TIME,
            'modifiedby' => $this->userid
        );
        $state = $this->section_model->update($up_data, array('sectionid'=>$sid));
        if($state){
            cpmessage("编辑成功！", "/index.php?d=admin&c=section&m=index&classid=$cid");
        }
        cpmessage("编辑失败！", "/index.php?d=admin&section&m=index&classid=$cid");
    }


    /**
     *  生成区块内容
     */
    public function make($sid = null)
    {
        //
    }


    /**
    *   获取区块类别
     */
    public function get_section_class(){
        $this->load->model("admin/section_class_model");
        return $this->section_class_model->ls();
    }


}
